//
//  CommentViewModel.m
//  meiyinxiang
//
//  Created by apple on 2018/1/17.
//  Copyright © 2018年 hbjApple. All rights reserved.
//
/*
 @property (nonatomic,strong) NSString *content;
 @property (nonatomic,strong) NSString *create_time;
 @property (nonatomic,strong) NSString *commentId;
 @property (nonatomic,strong) NSString *parent_id;
 @property (nonatomic,strong) NSString *rid;
 @property (nonatomic,strong) NSString *status;
 @property (nonatomic,strong) NSString *to_user_id;
 @property (nonatomic,strong) NSString *touserface;
 @property (nonatomic,strong) NSString *tousername;
 @property (nonatomic,strong) NSString *user_id;
 @property (nonatomic,strong) NSString *userface;
 @property (nonatomic,strong) NSString *username;
 */
#import "CommentViewModel.h"
#import "STInputBar.h"
#import "AppDelegate.h"
@interface CommentViewModel ()
{
    STInputBar *_inputBar;

}
@end
@implementation CommentViewModel
- (id)initWithModel:(CommentModel *)model{
    if (self = [super init]) {
        self.content = model.content;
        
        self.create_time = [MYXDateTimeHelper prettyDateWithTimestamp:model.create_time.longLongValue * 1000];
        self.commentId = model.commentId;
        self.parent_id = model.parent_id;
        self.rid = model.rid;
        self.status = model.status;
        self.to_user_id = model.to_user_id;
        self.touserface = model.touserface;
        self.tousername = model.tousername;
        self.user_id = model.user_id;
        self.userface = [NSString stringWithFormat:@"%@%@",MYXIMGBaseUrl,model.userface];
        self.username = model.username;
        self.bigid = model.bigid;
        self.count = model.count;
        self.rp_user_id = model.rp_user_id;
    }
    return self;
}
- (void)showCommentTextWithFinshBlock:(finishLeaveMessageBlock)leavemsgBlock {
    
  //  self.finishmsgBlock = leavemsgBlock;
    [self createCommentsView];
    // [commentText becomeFirstResponder];//再次让textView成为第一响应者（第二次）这次键盘才成功显示
}
#pragma mark - 添加键盘
- (void)hidekeybord{
    [_inputBar removeFromSuperview];
    _inputBar = nil;
}
- (void)createCommentsView {
    if (!_inputBar) {
        
        _inputBar = [STInputBar inputBar];
        _inputBar.center = CGPointMake(CGRectGetWidth(ApplicationDelegate.window.frame)/2, CGRectGetHeight(ApplicationDelegate.window.bounds)-CGRectGetHeight(_inputBar.frame)+CGRectGetHeight(_inputBar.frame)/2);
        [_inputBar setFitWhenKeyboardShowOrHide:YES];
        _inputBar.placeHolder = @"来说点什么吧...";
    }
    [ApplicationDelegate.window addSubview:_inputBar];
    __weak typeof(self) weakSelf = self;
    [_inputBar setDidSendClicked:^(NSString *text) {
        if (text.length > 0) {
            [[MYXHttpManager shared] leaveMoreContentWithLuckyMoneyId:weakSelf.rid content:text to_user_id:weakSelf.user_id rp_user_id:weakSelf.rp_user_id result:^(BOOL sucess, NSString *msg) {
                if (sucess) {
                    [weakSelf hidekeybord];
                    if (weakSelf.finishmsgBlock) {
                        weakSelf.finishmsgBlock(YES);
                    }
                }else{
                    ShowSVProgressErrorMessage(msg);
                }
            }];
        }
    }];
}

@end
